package logic

import (
	"context"
	"develop/model/mysql"
	"develop/usersrpc/internal/svc"
	"develop/usersrpc/usersrpc"
	"errors"
	"github.com/zeromicro/go-zero/core/logx"
)

type CollectDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectDelLogic {
	return &CollectDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectDelLogic) CollectDel(in *usersrpc.CollectDelRequest) (*usersrpc.CollectDelResponse, error) {
	// todo: add your logic here and delete this line
	var findUserId mysql.User_info
	err := findUserId.FindId(mysql.DB, in.UserId)
	if err != nil {
		return nil, err
	}
	if findUserId.ID == 0 {
		return nil, errors.New("用户不存在")
	}
	collectionInfo := mysql.Collection_Info{

		User_id: int(in.UserId),
	}
	err = collectionInfo.DelCollect(mysql.DB, in.UserId)
	if err != nil {
		return nil, err
	}
	return &usersrpc.CollectDelResponse{}, nil
}
